# -*- coding: utf8 -*-

from google.appengine.ext import db

# 用户
class User(db.Model):
    # 用户ID
    user_id = db.StringProperty(required = True)
    
    # 用户密码
    password = db.StringProperty(required = True)
    
    # 认证码
    auth_token = db.StringProperty(required = False)
    
    # 认证码过期时间
    auth_expire = db.DateTimeProperty(required = False)
    
    # 电子邮件
    email = db.EmailProperty(required = False)
    
    # 同步版本
    sync_version = db.IntegerProperty(required = True)
    
    def __str__(self):
        return u'User(%s, %s)' % (self.user_id, self.email)

class Payment(db.Model):
    # 用户ID
    user_id = db.StringProperty(required = True)
    
    # 客户端序列, 每个用户有自己的序列
    sequence = db.IntegerProperty(required = True)
    
    # 金额
    amount = db.FloatProperty(required = True)
    
    # 收入/支出
    balance = db.StringProperty(required = True)
    
    # 种类
    category = db.CategoryProperty(required = False);
    
    # 描述
    description = db.TextProperty(required = False)
    
    # 发生日
    event_date = db.DateProperty(required = True)
    
    # 最后更新日
    last_updated = db.DateTimeProperty(required = True)
    
    def __str__(self):
        return u'Payment(%s, %d)' % (self.user_id, self.sequence)
    
class PaymentCategory(db.Model):
    # 用户ID
    user_id = db.StringProperty(required = True)

    # 种类
    category = db.CategoryProperty(required = True);

    def __str__(self):
        return u'PaymentCategory(%s, %d)' % (self.user_id, self.category)

